import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qf.MpApplication;
import com.qf.mapper.UserMapper;
import com.qf.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest(classes = MpApplication.class)
@RunWith(SpringRunner.class)
public class testUser {
    @Autowired
    private UserMapper userMapper;
    private User user;
    @Test
    public void test(){
//        List<User> userList = userMapper.selectList(null);
//        System.out.println(userList);

//    User user =new User();
//    user.setAge(18);
//    user.setUserName("lihu");
//    user.setEmail("qq@qq.com");
//    user.setPassword("123");
//    user.setName("李虎");
//        int insert = userMapper.insert(user);
//        System.out.println(insert);

//        user.setId(6L);
//        user.setName("李发发");
//        int update = userMapper.updateById(user);

//        int delete = userMapper.deleteById(6);

//测试条件构造器
        QueryWrapper<User> queryWrapper =new QueryWrapper<>();
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //eq相当于equal 等于
//        QueryWrapper<User> age = queryWrapper.eq("age", 18);

//        LambdaQueryWrapper<User> age = lambdaQueryWrapper.eq(User::getAge, 25);
        
        //gt 大于  ge大于等于
//        QueryWrapper<User> age = queryWrapper.gt("age", 20);
       //lt小于   le小于等于
//        QueryWrapper<User> age = queryWrapper.lt("age", 20);
//        QueryWrapper<User> age = queryWrapper.ge("age", 20).or().le("age", 30);
//        QueryWrapper<User> age = queryWrapper.ge("age", 20).le("age", 30);
//        QueryWrapper<User> like = queryWrapper.like("name", "李");
        
        //LambdaQueryWrapper<User> like = lambdaQueryWrapper.like(User::getUserName, "李");

        //        QueryWrapper<User> like = queryWrapper.likeLeft("name","李");

//        QueryWrapper<User> like = queryWrapper.likeRight("name","李");
//   排序     QueryWrapper<User> order = queryWrapper.orderBy(true, true, "age");


       // LambdaQueryWrapper<User> order = lambdaQueryWrapper.orderBy(true, true, User::getAge);


        //QueryWrapper<User> order = queryWrapper.orderBy(true, true, "age","id");
//    降序    QueryWrapper<User> order = queryWrapper.orderByDesc(true,  "age");
//  升序      QueryWrapper<User> order = queryWrapper.orderByAsc(true, "age");

//        List<User> list = userMapper.selectList(order);
//        for (User user :list){
//            System.out.println(user);
//        }

        User user =new User();
       user.setId(1l);
        user.setName("张三");
        UpdateWrapper<User> updateWrapper =new UpdateWrapper<>();
        UpdateWrapper<User> age = updateWrapper.set("name", "222");

        int update = userMapper.update(user,age);
        System.out.println(update);


    }

}
